﻿package com.hongguan.oms.service.grid;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.hongguan.oms.domain.grid.GridUnit;
import com.hongguan.oms.domain.grid.GridUnitExample;
import com.hongguan.oms.service.BaseExampleService;

/**
 * GridUnit Service
 * 
 * @author
 * 
 */
@Service
public class GridUnitService extends
		BaseExampleService<GridUnit, GridUnitExample> {

	public GridUnitService() {
		namespace = "GRID_UNIT";
	}

	/**
	 * 保存GridUnit
	 * 
	 * @param gridunit
	 * 
	 */
	public void saveGridUnit(GridUnit gridunit) {
		if (gridunit.getUnitId() == null) {
			insert(gridunit);
		} else {
			updateByPrimaryKey(gridunit);
		}
	}

	/**
	 * public GisInfo getGisInfo(Long id){ return (GisInfo)
	 * getSqlMapClientTemplate().queryForObject("GIS_INFO.getGisInfo", id); }
	 */

	/**
	 * 根据ID获取营销单元
	 */
	public GridUnit getGridUnit(Long id) {
		return (GridUnit) getSqlMapClientTemplate().queryForObject(
				"GRID_UNIT.selectById", id);
	}

	/**
	 * 删除GridUnit
	 * 
	 * @param gridunit
	 *            　GridUnit
	 */
	public void deleteGridUnit(GridUnit gridunit) {
		deleteByPrimaryKey(gridunit);
	}

	public long addUnit(Map param) {
		return (Long) getSqlMapClientTemplate().insert("GRID_UNIT.unit_add",
				param);
	}

	public void modifyUnit(Map param) {
		getSqlMapClientTemplate().update("GRID_UNIT.unit_modify", param);
	}

	/**
	 * 取得营销单元列表信息
	 * 
	 * @param map
	 */
	public List searchGridUnit(Map<String, Object> map) {
		return getSqlMapClientTemplate().queryForList(
				namespace + ".searchGridUnit", map);
	}

	/**
	 * 根据区域id取得营销单元列表信息
	 * 
	 * @param map
	 */
	public List searchUnitByParam(Map map) {
		return getSqlMapClientTemplate().queryForList(
				namespace + ".searchUnitByParam", map);
	}

	/**
	 * 取得营销单元列表记录数
	 * 
	 * @param param
	 * @return
	 */
	public Long searchGridUnitCount(Map<String, Object> map) {
		return (Long) getSqlMapClientTemplate().queryForObject(
				namespace + ".searchGridUnitCount", map);
	}
}
